/**
 *
 */
import OpenApi;
import OpenApi.OpenApiUtil;

extends OpenApi;


init(config: OpenApiUtil.Config){
  super(config);
  @endpointRule = 'central';
  
  checkConfig(config);
  @endpoint = getEndpoint('yundun-dbaudit', @regionId, @endpointRule, @network, @suffix, @endpointMap, @endpoint);
}

function getEndpoint(productId: string, regionId: string, endpointRule: string, network: string, suffix: string, endpointMap: map[string]string, endpoint: string) throws: string{
  if (!$isNull(endpoint)) {
    return endpoint;
  }
  
  if (!$isNull(endpointMap) && !$isNull(endpointMap[regionId])) {
    return endpointMap[regionId];
  }
  return OpenApiUtil.getEndpointRules(productId, regionId, endpointRule, network, suffix);
}

model ClearInstanceStorageRequest {
  instanceId?: string(name='InstanceId', description='This parameter is required.', example='dbaudit-cn-78v1gc****'),
  lang?: string(name='Lang'),
  regionId?: string(name='RegionId', example='cn-hangzhou'),
  storageCategory?: string(name='StorageCategory', description='This parameter is required.', example='dbaudit-audit-dbaudit-cn-78v1gc****'),
  storageSpace?: string(name='StorageSpace', description='This parameter is required.', example='dbaudit-cn-78v1gc****'),
}

model ClearInstanceStorageResponseBody = {
  instanceId?: string(name='InstanceId', example='dbaudit-cn-78v1gc****'),
  requestId?: string(name='RequestId', example='482EF142-BFA5-43FF-B4B0-84A4B0763639'),
}

model ClearInstanceStorageResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: ClearInstanceStorageResponseBody(name='body'),
}

/**
 * @summary 清理SLS存储空间
 *
 * @param request ClearInstanceStorageRequest
 * @param runtime runtime options for this request RuntimeOptions
 * @return ClearInstanceStorageResponse
 */
async function clearInstanceStorageWithOptions(request: ClearInstanceStorageRequest, runtime: $RuntimeOptions): ClearInstanceStorageResponse {
  request.validate();
  var query = {};
  if (!$isNull(request.instanceId)) {
    query['InstanceId'] = request.instanceId;
  }
  if (!$isNull(request.lang)) {
    query['Lang'] = request.lang;
  }
  if (!$isNull(request.regionId)) {
    query['RegionId'] = request.regionId;
  }
  if (!$isNull(request.storageCategory)) {
    query['StorageCategory'] = request.storageCategory;
  }
  if (!$isNull(request.storageSpace)) {
    query['StorageSpace'] = request.storageSpace;
  }
  var req = new OpenApiUtil.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApiUtil.Params{
    action = 'ClearInstanceStorage',
    version = '2019-12-09',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  if ($isNull(@signatureVersion) || @signatureVersion != 'v4') {
    return callApi(params, req, runtime);
  } else {
    return execute(params, req, runtime);
  }
}

/**
 * @summary 清理SLS存储空间
 *
 * @param request ClearInstanceStorageRequest
 * @return ClearInstanceStorageResponse
 */
async function clearInstanceStorage(request: ClearInstanceStorageRequest): ClearInstanceStorageResponse {
  var runtime = new $RuntimeOptions{};
  return clearInstanceStorageWithOptions(request, runtime);
}

model DescribeInstanceAttributeRequest {
  instanceId?: string(name='InstanceId', description='This parameter is required.', example='dbaudit-cn-78v1gc****'),
  lang?: string(name='Lang'),
  regionId?: string(name='RegionId', example='cn-hangzhou'),
}

model DescribeInstanceAttributeResponseBody = {
  instanceAttribute?: {
    description?: string(name='Description', example='API'),
    expireTime?: long(name='ExpireTime', example='1578067200000'),
    instanceId?: string(name='InstanceId', example='dbaudit-cn-78v1gc****'),
    instanceStatus?: string(name='InstanceStatus', example='RUNNING'),
    internetEndpoint?: string(name='InternetEndpoint', example='tsiqvqjjlq-public.dbaudit.aliyuncs.com'),
    intranetEndpoint?: string(name='IntranetEndpoint', example='tsiqvqjjlq.dbaudit.aliyuncs.com'),
    licenseCode?: string(name='LicenseCode', example='alpha.professional'),
    publicNetworkAccess?: boolean(name='PublicNetworkAccess', example='true'),
    regionId?: string(name='RegionId', example='cn-hangzhou'),
    seriesCode?: string(name='SeriesCode', example='alpha'),
    startTime?: long(name='StartTime', example='1577437765000'),
    vpcId?: string(name='VpcId', example='vpc-bp1c85tzgqu1bf5b****'),
    vswitchId?: string(name='VswitchId', example='vsw-bp1kep1f0k5fnyfs****'),
    whiteList?: [ string ](name='WhiteList'),
  }(name='InstanceAttribute'),
  requestId?: string(name='RequestId', example='28382024-466D-4641-A144-40FD0DD53766'),
}

model DescribeInstanceAttributeResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: DescribeInstanceAttributeResponseBody(name='body'),
}

/**
 * @summary 获取实例属性
 *
 * @param request DescribeInstanceAttributeRequest
 * @param runtime runtime options for this request RuntimeOptions
 * @return DescribeInstanceAttributeResponse
 */
async function describeInstanceAttributeWithOptions(request: DescribeInstanceAttributeRequest, runtime: $RuntimeOptions): DescribeInstanceAttributeResponse {
  request.validate();
  var query = {};
  if (!$isNull(request.instanceId)) {
    query['InstanceId'] = request.instanceId;
  }
  if (!$isNull(request.lang)) {
    query['Lang'] = request.lang;
  }
  if (!$isNull(request.regionId)) {
    query['RegionId'] = request.regionId;
  }
  var req = new OpenApiUtil.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApiUtil.Params{
    action = 'DescribeInstanceAttribute',
    version = '2019-12-09',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  if ($isNull(@signatureVersion) || @signatureVersion != 'v4') {
    return callApi(params, req, runtime);
  } else {
    return execute(params, req, runtime);
  }
}

/**
 * @summary 获取实例属性
 *
 * @param request DescribeInstanceAttributeRequest
 * @return DescribeInstanceAttributeResponse
 */
async function describeInstanceAttribute(request: DescribeInstanceAttributeRequest): DescribeInstanceAttributeResponse {
  var runtime = new $RuntimeOptions{};
  return describeInstanceAttributeWithOptions(request, runtime);
}

model DescribeInstanceStorageRequest {
  instanceId?: string(name='InstanceId', description='This parameter is required.', example='dbaudit-cn-78v1gc****'),
  lang?: string(name='Lang'),
  regionId?: string(name='RegionId', example='cn-hangzhou'),
}

model DescribeInstanceStorageResponseBody = {
  instanceStorages?: [ 
    {
      storageCapacity?: long(name='StorageCapacity', example='6047313952768'),
      storageCategory?: string(name='StorageCategory', example='dbaudit-audit-dbaudit-cn-78v1gc****'),
      storageSpace?: string(name='StorageSpace', example='dbaudit-cn-78v1gc****'),
      storageTime?: long(name='StorageTime', example='180'),
      storageUsed?: long(name='StorageUsed', example='0'),
    }
  ](name='InstanceStorages'),
  requestId?: string(name='RequestId', example='4226E2BB-EED8-4067-B31B-7F02966765B2'),
}

model DescribeInstanceStorageResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: DescribeInstanceStorageResponseBody(name='body'),
}

/**
 * @summary 获取存储大小
 *
 * @param request DescribeInstanceStorageRequest
 * @param runtime runtime options for this request RuntimeOptions
 * @return DescribeInstanceStorageResponse
 */
async function describeInstanceStorageWithOptions(request: DescribeInstanceStorageRequest, runtime: $RuntimeOptions): DescribeInstanceStorageResponse {
  request.validate();
  var query = {};
  if (!$isNull(request.instanceId)) {
    query['InstanceId'] = request.instanceId;
  }
  if (!$isNull(request.lang)) {
    query['Lang'] = request.lang;
  }
  if (!$isNull(request.regionId)) {
    query['RegionId'] = request.regionId;
  }
  var req = new OpenApiUtil.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApiUtil.Params{
    action = 'DescribeInstanceStorage',
    version = '2019-12-09',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  if ($isNull(@signatureVersion) || @signatureVersion != 'v4') {
    return callApi(params, req, runtime);
  } else {
    return execute(params, req, runtime);
  }
}

/**
 * @summary 获取存储大小
 *
 * @param request DescribeInstanceStorageRequest
 * @return DescribeInstanceStorageResponse
 */
async function describeInstanceStorage(request: DescribeInstanceStorageRequest): DescribeInstanceStorageResponse {
  var runtime = new $RuntimeOptions{};
  return describeInstanceStorageWithOptions(request, runtime);
}

model DescribeInstancesRequest {
  getCenterInstance?: boolean(name='GetCenterInstance'),
  instanceId?: [ string ](name='InstanceId', example='dbaudit-cn-78v1gc****'),
  instanceStatus?: string(name='InstanceStatus', example='RUNNING'),
  lang?: string(name='Lang'),
  pageNumber?: int32(name='PageNumber', example='1'),
  pageSize?: int32(name='PageSize', example='10'),
  regionId?: string(name='RegionId', example='cn-hangzhou'),
  resourceGroupId?: string(name='ResourceGroupId', example='rg-acfm26ougij6****'),
  tag?: [ 
    {
      key?: string(name='Key', example='test'),
      value?: string(name='Value', example='testapi'),
    }
  ](name='Tag'),
}

model DescribeInstancesResponseBody = {
  instances?: [ 
    {
      description?: string(name='Description'),
      expireTime?: long(name='ExpireTime', example='1578067200000'),
      instanceId?: string(name='InstanceId', example='dbaudit-cn-78v1gc****'),
      instanceStatus?: string(name='InstanceStatus', example='RUNNING'),
      internetEndpoint?: string(name='InternetEndpoint', example='tsiqvqjjlq-public.dbaudit.aliyuncs.com'),
      intranetEndpoint?: string(name='IntranetEndpoint', example='tsiqvqjjlq.dbaudit.aliyuncs.com'),
      licenseCode?: string(name='LicenseCode', example='alpha.professional'),
      publicNetworkAccess?: boolean(name='PublicNetworkAccess', example='true'),
      regionId?: string(name='RegionId', example='cn-hangzhou'),
      seriesCode?: string(name='SeriesCode', example='alpha'),
      startTime?: long(name='StartTime', example='1577437765000'),
      vpcId?: string(name='VpcId', example='vpc-bp1c85tzgqu1bf5b****'),
      vswitchId?: string(name='VswitchId', example='vsw-bp1kep1f0k5fnyfs****'),
    }
  ](name='Instances'),
  requestId?: string(name='RequestId', example='12AA0353-F01D-43E2-A85C-9040F7A35D93'),
  totalCount?: long(name='TotalCount', example='18'),
}

model DescribeInstancesResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: DescribeInstancesResponseBody(name='body'),
}

/**
 * @summary 获取实例列表
 *
 * @param request DescribeInstancesRequest
 * @param runtime runtime options for this request RuntimeOptions
 * @return DescribeInstancesResponse
 */
async function describeInstancesWithOptions(request: DescribeInstancesRequest, runtime: $RuntimeOptions): DescribeInstancesResponse {
  request.validate();
  var query = {};
  if (!$isNull(request.getCenterInstance)) {
    query['GetCenterInstance'] = request.getCenterInstance;
  }
  if (!$isNull(request.instanceId)) {
    query['InstanceId'] = request.instanceId;
  }
  if (!$isNull(request.instanceStatus)) {
    query['InstanceStatus'] = request.instanceStatus;
  }
  if (!$isNull(request.lang)) {
    query['Lang'] = request.lang;
  }
  if (!$isNull(request.pageNumber)) {
    query['PageNumber'] = request.pageNumber;
  }
  if (!$isNull(request.pageSize)) {
    query['PageSize'] = request.pageSize;
  }
  if (!$isNull(request.regionId)) {
    query['RegionId'] = request.regionId;
  }
  if (!$isNull(request.resourceGroupId)) {
    query['ResourceGroupId'] = request.resourceGroupId;
  }
  if (!$isNull(request.tag)) {
    query['Tag'] = request.tag;
  }
  var req = new OpenApiUtil.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApiUtil.Params{
    action = 'DescribeInstances',
    version = '2019-12-09',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  if ($isNull(@signatureVersion) || @signatureVersion != 'v4') {
    return callApi(params, req, runtime);
  } else {
    return execute(params, req, runtime);
  }
}

/**
 * @summary 获取实例列表
 *
 * @param request DescribeInstancesRequest
 * @return DescribeInstancesResponse
 */
async function describeInstances(request: DescribeInstancesRequest): DescribeInstancesResponse {
  var runtime = new $RuntimeOptions{};
  return describeInstancesWithOptions(request, runtime);
}

model ListTagResourcesRequest {
  nextToken?: string(name='NextToken', example='52EcpzBpR86EEpcc.9xyfvym3cKAXsdV2SSFZnouWTRzf1'),
  regionId?: string(name='RegionId', description='This parameter is required.', example='cn-hangzhou'),
  resourceId?: [ string ](name='ResourceId', example='dbaudit-cn-78v1gc****'),
  resourceType?: string(name='ResourceType', description='This parameter is required.', example='INSTANCE'),
  tag?: [ 
    {
      key?: string(name='Key', example='test'),
      value?: string(name='Value', example='testapi'),
    }
  ](name='Tag'),
}

model ListTagResourcesResponseBody = {
  nextToken?: string(name='NextToken', example='52EcpzBpR86EEpcc.9xyfvym3cKAXsdV2SSFZnouWTRzf1'),
  requestId?: string(name='RequestId', example='E6A08A8A-F962-4FAD-AF0C-86B393E1F9C1'),
  tagResources?: [ 
    {
      resourceId?: string(name='ResourceId', example='dbaudit-cn-78v1gc****'),
      resourceType?: string(name='ResourceType', example='INSTANCE'),
      tagKey?: string(name='TagKey', example='test'),
      tagValue?: string(name='TagValue', example='testapi'),
    }
  ](name='TagResources'),
}

model ListTagResourcesResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: ListTagResourcesResponseBody(name='body'),
}

/**
 * @param request ListTagResourcesRequest
 * @param runtime runtime options for this request RuntimeOptions
 * @return ListTagResourcesResponse
 */
async function listTagResourcesWithOptions(request: ListTagResourcesRequest, runtime: $RuntimeOptions): ListTagResourcesResponse {
  request.validate();
  var query = {};
  if (!$isNull(request.nextToken)) {
    query['NextToken'] = request.nextToken;
  }
  if (!$isNull(request.regionId)) {
    query['RegionId'] = request.regionId;
  }
  if (!$isNull(request.resourceId)) {
    query['ResourceId'] = request.resourceId;
  }
  if (!$isNull(request.resourceType)) {
    query['ResourceType'] = request.resourceType;
  }
  if (!$isNull(request.tag)) {
    query['Tag'] = request.tag;
  }
  var req = new OpenApiUtil.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApiUtil.Params{
    action = 'ListTagResources',
    version = '2019-12-09',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  if ($isNull(@signatureVersion) || @signatureVersion != 'v4') {
    return callApi(params, req, runtime);
  } else {
    return execute(params, req, runtime);
  }
}

/**
 * @param request ListTagResourcesRequest
 * @return ListTagResourcesResponse
 */
async function listTagResources(request: ListTagResourcesRequest): ListTagResourcesResponse {
  var runtime = new $RuntimeOptions{};
  return listTagResourcesWithOptions(request, runtime);
}

